//=============================================================================
//	S E N S I R I O N	AG,	Laubisruetistr. 50, CH-8712 Staefa, Switzerland
//=============================================================================
// Project	:	SHT3x Sample Code (V1.1)
// File	:	i2c_hal.h (V1.1)
// Author	:	RFU
// Date	:	6-Mai-2015
// Controller:	STM32F100RB
// IDE	:	µVision V5.12.0.0
// Compiler	:	Armcc
// Brief	:	I2C hardware abstraction layer
//=============================================================================

#ifndef I2C_HAL_H
#define I2C_HAL_H

//-- Includes -----------------------------------------------------------------
#include "stm32f10x.h"
#include "Delay.h"

//-- Enumerations -------------------------------------------------------------
typedef enum {
    NO_ERROR = 0x00, // no error
    ACK_ERROR = 0x01, // no acknowledgment error
    CHECKSUM_ERROR = 0x02, // checksum mismatch error
    TIMEOUT_ERROR = 0x04, // timeout error
    PARM_ERROR = 0x80, // parameter out of range error
} etError;

// I2C acknowledge
typedef enum {
    ACK	= 0,
    NACK = 1,
} etI2cAck;

typedef	unsigned char	u8t;	///<	range:	0 .. 255
typedef	signed char	    i8t;	///<	range:	-128 .. +127
typedef	unsigned short	u16t;	///<	range:	0 .. 65535
typedef	signed short	i16t;	///<	range:	-32768 .. +32767
typedef	unsigned long	u32t;	///<	range:	0 .. 4'294'967'295
typedef	signed long	    i32t;	///<	range:	-2'147'483'648 .. +2'147'483'647
typedef	float	        ft;	    ///<	range:	+-1.18E-38 .. +-3.39E+38
typedef	double	        dt;	    ///<	range:	.. +-1.79E+308
typedef enum {
    FALSE = 0,
    TRUE = 1
} bt;
//=============================================================================
void I2c_Init(void);
//=============================================================================
// Initializes the ports for I2C interface.
//-----------------------------------------------------------------------------

//=============================================================================
void I2c_StartCondition(void);
//=============================================================================
// Writes a start condition on I2C-Bus.
//-----------------------------------------------------------------------------
// remark: Timing (delay) may have to be changed for different microcontroller.
//
// SDA:	|
//
// SCL:	|

//=============================================================================
void I2c_StopCondition(void);
//=============================================================================
// Writes a stop condition on I2C-Bus.
//-----------------------------------------------------------------------------
// remark: Timing (delay) may have to be changed for different microcontroller.
//
// SDA:	 	|
//
// SCL:	 	|

//=============================================================================
etError I2c_WriteByte(u8t txByte);
//=============================================================================
// Writes a byte to I2C-Bus and checks acknowledge.
//-----------------------------------------------------------------------------
// input:	txByte	transmit byte


//
// return: error:	ACK_ERROR = no acknowledgment from sensor
//	NO_ERROR	= no error
//
// remark: Timing (delay) may have to be changed for different microcontroller.

//=============================================================================
etError I2c_ReadByte(u8t *rxByte, etI2cAck ack, u8t timeout);

etError I2c_GeneralCallReset(void);

#endif
